package logic

import (
	"context"
	"fmt"
	"gitee.com/A1001574000/feedback-rpc/feedback"
	"gitee.com/A1001574000/feedback-rpc/internal/svc"
	"gitee.com/A1001574000/feedback-rpc/server"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserFeedbackLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserFeedbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFeedbackLogic {
	return &UserFeedbackLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserFeedbackLogic) UserFeedback(in *feedback.UserFeedbackRequest) (*feedback.UserFeedbackResponse, error) {
	if in == nil {
		return &feedback.UserFeedbackResponse{}, fmt.Errorf("内容不能为空")
	}
	if in.UserFeedback.UserId == 0 {
		return &feedback.UserFeedbackResponse{}, fmt.Errorf("用户 id 不能为空")
	}
	if in.UserFeedback.ContactWay == "" {
		return &feedback.UserFeedbackResponse{}, fmt.Errorf("用户联系方式不能为空")
	}
	createFeedback, err := server.CreateFeedback(in.UserFeedback)
	if err != nil {
		return nil, err
	}
	return &feedback.UserFeedbackResponse{
		UserFeedback: createFeedback,
	}, nil
}
